from selenium.webdriver.common.by import By

from base.page_base import BasePage
from config import NAME, CARD


class OpenAccount(BasePage):
    """开通资金托管账户"""
    # 1.元素定位
    __click_open = (By.LINK_TEXT, "立即开通")
    __real_name = (By.NAME, "realname")
    __id_card = (By.NAME, "card_id")
    __confirm_btn = (By.CSS_SELECTOR, "[value='确认提交']")
    __act_now = (By.CSS_SELECTOR, ".btn.ng-scope")
    # 获取成功文本
    __success_text = (By.CSS_SELECTOR, "body")

    # 2.操作步骤方法
    def get_result_success_text(self):
        """获取成功文本"""
        return self.base_switch_handle(self.__success_text).text

    def click_account(self):
        """点击立即开通"""
        self.base_click(self.__click_open)

    def input_real_name(self, real_name):
        """输入真实姓名"""
        self.base_input(self.__real_name, real_name)


    def input_id_card(self, id_card):
        """输入身份证号"""
        self.base_input(self.__id_card, id_card)

    def click_confirm(self):
        """点击确认提交"""
        self.base_click(self.__confirm_btn)

    def click_act_now(self):
        """点击确认开通"""
        self.base_click(self.__act_now)

    # 3.业务方法
    def open_account(self, real_name=NAME, id_card=CARD):
        """开通资金托管账号"""
        self.click_account()
        self.input_real_name(real_name)
        self.input_id_card(id_card)
        self.click_confirm()
        self.click_act_now()
